<template>
	<!-- 添加或修改岗位管理对话框 -->
	<el-dialog :title="dialogTitle" :visible.sync="visible" width="600px" append-to-body>
		<el-form ref="form" :model="formData" :rules="formRules" label-width="86px">
			<el-row :gutter="16">
				<el-col :span="24">
					<el-form-item label="岗位名称" prop="postName">
						<el-input v-model="formData.postName" placeholder="请输入岗位名称" />
					</el-form-item>
				</el-col>
				<el-col :span="11">
					<el-form-item label="涉密等级" prop="spPostLevel">
						<el-select v-model="formData.spPostLevel" placeholder="选择涉密等级" style="width: 100%">
							<el-option v-for="(item, index) in dictData.sp_level" :key="index" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="13">
					<el-form-item label="岗位确定依据" prop="postBasis" label-width="114px">
						<el-select v-model="formData.postBasis" placeholder="请选择岗位确定依据" style="width: 100%">
							<el-option v-for="(item, index) in dictData.sp_post_basis" :key="index" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="11">
					<el-form-item label="最高学历" prop="highestDegree">
						<el-select v-model="formData.highestDegree" placeholder="请选择最高学历" style="width: 100%">
							<el-option v-for="(item, index) in dictData.sp_highest_degree" :key="index" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="13">
					<el-form-item label="管理干部类型" prop="managementType" label-width="114px">
						<el-select v-model="formData.managementType" placeholder="请选择管理干部类型" style="width: 100%">
							<el-option v-for="(item, index) in dictData.sp_leader_type" :key="index" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="11">
					<el-form-item label="岗位类型" prop="postType">
						<el-select v-model="formData.postType" placeholder="请选择岗位类型" style="width: 100%">
							<el-option v-for="(item, index) in dictData.sp_project_type" :key="index" :label="item.label" :value="item.value"></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="13">
					<el-form-item label="岗位人员" prop="spUserName" label-width="114px">
						<el-autocomplete v-model="formData.spUserName" v-bind="inputConfig" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="岗位职责" prop="postFunction">
						<el-input v-model="formData.postFunction" placeholder="请输入岗位职责" />
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="岗位说明" prop="remark">
						<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 6 }" v-model="formData.remark" placeholder="请输入岗位说明" />
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template slot="footer">
			<el-button type="primary" @click="handleSubmitData()">确定</el-button>
			<el-button @click="visible = false">取消</el-button>
		</template>
	</el-dialog>
</template>

<script>
import formMixins from '../common/formMixins';
import { listUser } from '@/api/personnal/person';
import { getSpPost, addSpPost, updateSpPost } from '@/api/personnal/spPost';
export default {
	mixins: [formMixins],
	data() {
		return {
			formName: '岗位',
			formRules: {
				postName: { required: true, message: '请输入岗位名称', trigger: 'blur' },
				postBasis: { required: true, message: '请选择开始日期', trigger: 'change' },
				spPostLevel: { required: true, message: '请选择截止日期', trigger: 'change' },
				highestDegree: { required: true, message: '请选择审批日期', trigger: 'change' },
				managementType: { required: true, message: '请选择管理干部类型', trigger: 'change' },
				postFunction: { required: true, message: '请输入岗位职责', trigger: 'blur' },
				postType: { required: true, message: '请选择岗位类型', trigger: 'change' },
				spUserName: { required: true, message: '请输入岗位人员', trigger: 'blur' }
			},
			inputConfig: {
				valueKey: 'name',
				triggerOnFocus: false,
				highlightFirstItem: true,
				placeholder: '请输入岗位人员',
				fetchSuggestions: this.handleFetchSuggest
			}
		};
	},
	computed: {
		detailFunction() {
			return eval(getSpPost);
		},
		callFunction() {
			return eval(this.addOrEdit ? addSpPost : updateSpPost);
		}
	},
	watch: {
		userDetail(data) {
			this.$set(this.formData, 'userName', data.name);
		}
	},
	methods: {
		//格式化请求参数
		formatRequestParams() {
			let params = { ...this.formData };
			return params;
		},
		async handleFetchSuggest(name, callback) {
			let result = await listUser({ name });
			if (result.code === 200) {
				callback(result.rows || []);
			} else {
				callback([]);
			}
		}
	}
};
</script>

<style scoped></style>
